import TreeTraversal.TreeNode;

import java.util.ArrayList;
import java.util.List;

public class rightSideView2 {
    public List<Integer> rightSideView(TreeNode root) {
        List<Integer> ans = new ArrayList<>();
        a(root,0,ans);
        return ans;
    }
    public void a(TreeNode root,int depth,List<Integer> ans){
        if(root == null){
            return;
        }
        if(ans.size() == depth){
            ans.add(root.val);
        }
        a(root.right,depth+1,ans);
        a(root.left,depth+1,ans);
    }
}
